using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Xml.Serialization;
using Jaws.Core.Web.Data;

namespace Jaws.Core.Web.Entities.Pages
{
    [Serializable]
    [XmlRoot("pages")]
    [XmlDataDirectory("pages")]
    public class PageCollection : XmlCollectionBase<PageCollection, Page>
    {
        

        internal PageCollection(IList<Page> list)
            : base(list)
        {
        }

        public PageCollection()
        {

        }

        /// <summary>
        /// Finds the name of the by.
        /// </summary>
        /// <param name="id">The name.</param>
        /// <returns></returns>
        public Page FindById(string id)
        {
            foreach (Page r in this)
            {
                if (string.Compare(r.Id.ToString(), id, true, CultureInfo.CurrentCulture) == 0) { return r; }
            }

            return null;
        }

        public Page GetHomePage()
        {
            Page page = null;
            var homePage = (from p in this where p.IsHomePage select p);
            if (homePage != null) return homePage as Page;
            return page;
        }

    }
}